package com.bitrate.dagger.server.mqtt.service;

import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.dreamlu.iot.mqtt.spring.server.MqttServerTemplate;

@Service
public class MqttService {

	private static final Logger logger = LoggerFactory.getLogger(MqttService.class);

	@Autowired
	private MqttServerTemplate mqttServerTemplate;

	public boolean publish(String clientId, String topic, String message) {
		logger.info("Mqtt Publish ClientId:{}", clientId);
		logger.info("Mqtt Publish Topic:{}", topic);
		logger.info("Mqtt Publish Message:{}", message);
		boolean result = mqttServerTemplate.publish(clientId, topic, message.getBytes(StandardCharsets.UTF_8));
		logger.info("Mqtt Publish Result:{}", result);
		return result;
	}
}
